package com.gg.util;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import java.io.IOException;

public class BaseCommon {

    /**
     * base 64 解密
     */
    public static String decrypt(String text) throws IOException {
        final BASE64Decoder decoder = new BASE64Decoder();
        return new String(decoder.decodeBuffer(text), "UTF-8");
    }

    /**
     * 编码
     * @param text
     * @return
     * @throws IOException
     */
    public static Object codebase(String text) throws IOException {
        final BASE64Encoder encoder = new BASE64Encoder();
        final String encodedText = encoder.encode(text.getBytes("UTF-8"));
        return encodedText;
    }

    public static void main(String args[]) throws IOException {

        System.out.println(codebase("a"));
        System.out.println(decrypt("YQ=="));
    }
}
